﻿var phone = sessionStorage.getItem("userPhone");
var recCount = 0;
$(function () {
    $(".try select").change(function () {
        var options = $(".try select option:selected");
        $.post("/Home/GetShopListMethod", { 'cityId': options.val(), 'pageType': 1 }, GetFreeShopMethodResponse);
    })
    //$(".lists .lists-content").click(function () {
    //    $(".volume-frame").show();
    //});
    $(".volume-frame .close-img").click(function () {
        $(".volume-frame").hide();
    });

    PageClick();
})


var shopName = "";
var ticketName = "";
function RecTicket(shopId, sName, tName) {
    var isRec = $("#ticketShopId").val();
    if (isRec > 0)
        return layer.msg("每人限领一张！");
    shopName = sName;
    ticketName = tName;
    $.post("/Home/RecFreeTicket", { 'phone': phone, 'shopId': shopId }, GetRecFreeTicketResponse);
}


function GetRecFreeTicketResponse(data) {

    if (data.Success) {
        window.location.href = "/Home/RecTicketSuccess?name=" + shopName + "&ticketName="+ticketName;
    }

    layer.msg(data.Message);
}

function PageClick() {
    $.post("/Home/PageClick", { 'phone': phone, 'pageType': 1 });
}
function GetFreeShopMethodResponse(data) {
    if (data.Success) {
        var r = data.Message;
        $(".chengdu img").attr("src", "../image/city/" + data.CityId + ".png")
        var str = "";
        var shop = $("#ticketShopId").val();
        if (r.length > 0) {
            for (var i = 0; i < r.length; i++) {
                var strshop = "";
                if (r[i].CityName.length > 1)
                    strshop = "(" + r[i].CityName + ")";

                str += '<div class="lists"><div class="lists-content" onclick="ShopDetails(' + r[i].ShopId + ',1)">';
                str += '<img src="../image/shoptype/shop_' + r[i].ShopType + '.png" alt=""><div class="lists-logo">';
                str += '<img src="http://fuwu.xdjsclub.com/Shops/images/' + r[i].ImgLogo + '/logo.jpg" /><p>' + r[i].ShopName + strshop + '</p><p>' + r[i].TicketName + '</p></div></div>';
                str += '<div class="lists-btn">';
                if (shop == r[i].ShopId) {
                    str += '<img src="../image/current/btn-lingqu2.png"  alt="已领取按钮" />  ';
                } else {
                    str += '<img src="../image/free/btn-lingqu.png" onclick="RecTicket(' + r[i].ShopId + ',\'' + r[i].ShopName + '\',\'' + r[i].TicketName + '\')" alt="领取按钮">';
                }
                str += '</div></div>';
            }
        }
        $(".menu").html(str);

    } else {
        layer.msg("系统繁忙，请稍后再试！");
    }
}

